import 'package:flutter/material.dart';
import 'package:stroke_customer/model/comm/CommDic.dart';



//TODO 调用接口

class DicPage extends StatefulWidget {

  int code;
  String title;


  DicPage(this.code, this.title);

  @override
  State<StatefulWidget> createState() {

    return new DicPageState();
  }

}




class DicPageState extends State<DicPage> {

  var value;


  @override
  void initState() {
    super.initState();
    int code = widget.code;
    dic = _initData();
  }

  CommDic _initData() {
    Data data = new Data(
        1,
        "1",
        "1",
        1001,
        "百姓端",
        -1,
        "",
        "",
        1,
        "",
        "");
    Data data1 = new Data(
        1,
        "1",
        "1",
        1002,
        "医生端",
        -1,
        "",
        "",
        1,
        "",
        "");
    Data data2 = new Data(
        1,
        "1",
        "1",
        1003,
        "急救端",
        -1,
        "",
        "",
        1,
        "",
        "");
    Data data3 = new Data(
        1,
        "1",
        "1",
        1004,
        "监控端",
        -1,
        "",
        "",
        1,
        "",
        "");

    List<Data> dataList = new List();
    dataList.add(data);
    dataList.add(data1);
    dataList.add(data2);
    dataList.add(data3);

    print(dataList.length.toString() + "******************");

    CommDic dic = new CommDic(dataList, "0", "aa");
    return dic;
  }

  CommDic dic;

  List<DropdownMenuItem> _getDropdownMenuItem() {
    List<DropdownMenuItem> items = new List();

    print("_getDropdownMenuItem"+dic.data.length.toString());

    for (int i = 0;i<dic.data.length;i++) {
      Data item = dic.data[i];
      print("CommDic  "+item.codeName);
     DropdownMenuItem dropdownMenuItem = new DropdownMenuItem(
      child: new Text(item.codeName),
      value: item.codeValue.toString(),
     );

      items.add(dropdownMenuItem);
    }

    print("DropdownMenuItemList is "+items.length.toString());
    return items;
  }


  @override
  Widget build(BuildContext context) {
//    List<DropdownMenuItem> itemList=_getDropdownMenuItem();

    return
       new Scaffold(
         body:  Row(
           children: <Widget>[
            new Center(
              child:
              new DropdownButton(
                items: _getDropdownMenuItem(),
                hint: new Text("请选择数据"),
                value:value,
                onChanged: (T){//下拉菜单item点击之后的回调
                  setState(() {
                    value= T;
                    print("value is "+value.toString());
                  });
                },
                elevation: 24,
                style: new TextStyle(//设置文本框里面文字的样式
                    color: Colors.black
                ),
                iconSize: 50,
//                isDense: false,
//                isExpanded: true,

              ),
            )
           ],
         )

       );

  }

}